package bs.org.suite.util;

/**
 * From  sqlite-jdbc-3.7.2.jar  org.sqlite.OSInfo.java.
 * 
 * http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC.
 * 
 * Apache License version 2.0.
 * 
 * Modify by Baishui2004 2013-1-16.
 * 
 */
public class OSInfo {

	public static String OS_WINDOWS = "Windows";
	public static String OS_MAC = "Mac";
	public static String OS_LINUX = "Linux";

	public static String OS_WINDOWS_ARCH_X86 = "Windows/x86";
	public static String OS_WINDOWS_ARCH_AMD64 = "Windows/amd64";
	public static String OS_MAC_ARCH_I386 = "Mac/i386";
	public static String OS_MAC_ARCH_X86_64 = "Mac/x86_64";
	public static String OS_MAC_ARCH_PPC = "Mac/ppc";
	public static String OS_LINUX_ARCH_I386 = "Linux/i386";
	public static String OS_LINUX_ARCH_AMD64 = "Linux/amd64";

	public static Boolean isWindows() {
		return OS_WINDOWS.equals(getOSName());
	}

	public static Boolean isMac() {
		return OS_MAC.equals(getOSName());
	}

	public static Boolean isLinux() {
		return OS_LINUX.equals(getOSName());
	}

	public static String getNativeLibFolderPathForCurrentOS() {
		return getOSName() + "/" + getArchName();
	}

	public static String getOSName() {
		return translateOSNameToFolderName(System.getProperty("os.name"));
	}

	public static String getArchName() {
		return translateArchNameToFolderName(System.getProperty("os.arch"));
	}

	public static String translateOSNameToFolderName(String osName) {
		if (osName.contains(OS_WINDOWS)) {
			return OS_WINDOWS;
		} else if (osName.contains(OS_MAC)) {
			return OS_MAC;
		} else if (osName.contains(OS_LINUX)) {
			return OS_LINUX;
		} else {
			return osName.replaceAll("\\W", "");
		}
	}

	public static String translateArchNameToFolderName(String archName) {
		return archName.replaceAll("\\W", "");
	}
}
